package com.demo57_最后一个单词的长度;

public class Solution {
    public static void main(String[] args) {
        int length = lengthOfLastWord("fdajifj fdahhi  ");
        System.out.println(length);
    }
    public static int lengthOfLastWord(String s) {
        //1.对s做前后的空格的截断
        String trim = s.trim();
        int index = trim.lastIndexOf(" ");
        System.out.println("最后一个空格的索引是:"+index);
        int length = trim.length()-1 - index;
        return length;
    }
}

